package com.qf.smsplatform.webmaster.controller;

import com.qf.smsplatform.webmaster.dto.R;
import com.qf.smsplatform.webmaster.dto.UserDto;
import com.qf.smsplatform.webmaster.pojo.TAdminUser;
import com.qf.smsplatform.webmaster.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/users")
public class UserController {

    private UserService userService;

    @Autowired
    public void setUserService(UserService userService){
        this.userService = userService;
    }

    //临时需要一个登陆操作
    @PostMapping("/login")
    public R login(@RequestBody UserDto userDto, HttpSession session) {
        //给业务层处理
        TAdminUser user = userService.login(userDto);
        //返回结果
        session.setAttribute("user", user);
        return R.setOk();
    }
}
